<template>
  <BaseTable
    bordered
    :expanded-row-keys="expandedRowKeys"
    column-code="000574"
    :loading="packLoading"
    :height="180"
    :data-source="dataSource"
    :pagination="false"
    ,
    :exclude-columns="['action']"
  >
    <template #bodyCell="{ column, record }">
      <template v-if="column.dataIndex === 'link'">
        <div class="table-link"></div>
      </template>
      <template v-if="column.dataIndex === 'sfxm'">
        <MedicineInfo :value="{ mc: record.sfxm?.mc, gg: record.sfxm?.gg, cj: record.sfxm?.cj }" />
      </template>
      <template v-if="column.dataIndex === 'yf'">
        {{ record.yf?.fyff }}
      </template>
      <template v-if="column.dataIndex === 'jlsl'"> {{ record.jlsl || 0 }} {{ record.sfxm?.jldw }} </template>
      <template v-if="column.dataIndex === 'cfts'"> {{ record.cfts }}天 </template>
      <template v-if="column.dataIndex === 'sl'"> {{ record.sl }}{{ record.sfxm?.dw }} </template>
      <template v-if="column.dataIndex === 'pl'">
        {{ record.pl?.pl }}
      </template>
    </template>
  </BaseTable>
</template>
<script setup>
import { ref } from 'vue'

const props = defineProps({
  params: {
    type: Object,
    desc: '请求参数',
    default: () => ({})
  }
})

const expandedRowKeys = ref([])
const {
  loading: packLoading,
  tableData: dataSource,
  getData: getPackData
} = useTable({
  url: '/outp/template/getClinicalOrderPackageItemList',
  pagination: false,
  formatParams: () => {
    return {
      tcid: props.params?.tcid,
      czcf: 0
    }
  },
  onSuccess: (data) => {
    expandedRowKeys.value = data?.map((item) => 'row-key-' + item.id)
    dataSource.value = data?.map((child) => ({
      ...child,
      yf: child.yf || {},
      pl: child.pl || {},
      key: 'row-key-' + child.id,
      children: child.children ? child.children.map((c) => ({ ...c, yf: c.yf || {}, pl: c.pl || {}, isChild: true, cfbh: 0, fkey: child.id, key: c.id })) : []
    }))
  }
})

defineExpose({
  getPackData
})
</script>
<style lang="less" scoped>
:deep(.ant-table-row-expand-icon) {
  display: none;
}
</style>
